/*
 * My97 DatePicker 4.5
 * SITE: http://dp.my97.net
 * BLOG: http://my97.cnblogs.com
 * MAIL: smallcarrot@163.com
 */
var $dp, WdatePicker;
(function (R) {
    var $ = {
        $wdate: true,
        $dpPath: "",
        $crossFrame: true,
        position: {},
        lang: "auto",
        skin: "default",
        dateFmt: "yyyy-MM-dd",
        realDateFmt: "yyyy-MM-dd",
        realTimeFmt: "HH:mm:ss",
        realFullFmt: "%Date %Time",
        minDate: "1900-01-01 00:00:00",
        maxDate: "2099-12-31 23:59:59",
        startDate: "",
        alwaysUseStartDate: false,
        yearOffset: 1911,
        isShowWeek: false,
        highLineWeekDay: true,
        isShowClear: true,
        isShowToday: true,
        isShowOthers: true,
        readOnly: false,
        errDealMode: 0,
        autoPickDate: null,
        qsEnabled: true,

        disabledDates: null,
        disabledDays: null,
        opposite: false,
        onpicking: null,
        onpicked: null,
        onclearing: null,
        oncleared: null,
        eCont: null,
        vel: null,
        errMsg: "",
        quickSel: [],
        has: {}
    };
    WdatePicker = T;
    var W = window, O = "document", J = "documentElement", C = "getElementsByTagName", U, A, S, I, a;
    switch (navigator.appName) {
        case"Microsoft Internet Explorer":
            S = true;
            break;
        case"Opera":
            a = true;
            break;
        default:
            I = true;
            break
    }
    A = L();
    if ($.$wdate) M(A + "skin/WdatePicker.css");
    U = W;
    if ($.$crossFrame) {
        try {
            while (U.parent[O] != U[O] && U.parent[O][C]("frameset").length == 0) U = U.parent
        } catch (P) {
        }
    }
    if (!U.$dp) U.$dp = {
        ff: I,
        ie: S,
        opera: a,
        el: null,
        win: W,
        status: 0,
        defMinDate: $.minDate,
        defMaxDate: $.maxDate,
        flatCfgs: []
    };
    Q = U.$dp;
    if (Q.status == 0) Y(W, function () {
        T(null, true)
    });
    if (!W[O].docMD) {
        E(W[O], "onmousedown", D);
        W[O].docMD = true
    }
    if (!U[O].docMD) {
        E(U[O], "onmousedown", D);
        U[O].docMD = true
    }
    E(W, "onunload", function () {
        if (Q.dd) Q.dd.style.display = "none"
    });

    function B() {
        U.$dp = U.$dp || {};
        obj = {
            $: function ($) {
                return (typeof $ == "string") ? this.win[O].getElementById($) : $
            }, $D: function ($, _) {
                return this.$DV(this.$($).value, _)
            }, $DV: function (_, $) {
                if (_ != "") {
                    this.dt = Q.cal.splitDate(_, Q.cal.dateFmt);
                    if ($) for (var A in $) {
                        if (this.dt[A] === undefined) this.errMsg = "invalid property:" + A;
                        this.dt[A] += $[A]
                    }
                    if (this.dt.refresh()) return this.dt
                }
                return ""
            }, show: function () {
                if (this.dd) this.dd.style.display = "block"
            }, hide: function () {
                if (this.dd) this.dd.style.display = "none"
            }, attachEvent: E
        };
        for (var $ in obj) U.$dp[$] = obj[$];
        Q = U.$dp
    }

    function E(A, $, _) {
        if (S) A.attachEvent($, _); else {
            var B = $.replace(/on/, "");
            _._ieEmuEventHandler = function ($) {
                return _($)
            };
            A.addEventListener(B, _._ieEmuEventHandler, false)
        }
    }

    function L() {
        var _, A, $ = document.getElementsByTagName("script");
        for (var B = 0; B < $.length; B++) {
            _ = $[B].src.substring(0, $[B].src.toLowerCase().indexOf("WdatePicker.js"));
            A = _.lastIndexOf("/");
            if (A > 0) _ = _.substring(0, A + 1);
            if (_) break
        }
        return _
    }

    function F(F) {
        var E, C;
        if (F.substring(0, 1) != "/" && F.indexOf("://") == -1) {
            E = U.location.href;
            C = location.href;
            if (E.indexOf("?") > -1) E = E.substring(0, E.indexOf("?"));
            if (C.indexOf("?") > -1) C = C.substring(0, C.indexOf("?"));
            var _ = "", D = "", A = "", H, G, B = "";
            for (H = 0; H < Math.max(E.length, C.length); H++) if (E.charAt(H).toLowerCase() != C.charAt(H).toLowerCase()) {
                G = H;
                while (E.charAt(G) != "/") {
                    if (G == 0) break;
                    G -= 1
                }
                _ = E.substring(G + 1, E.length);
                _ = _.substring(0, _.lastIndexOf("/"));
                D = C.substring(G + 1, C.length);
                D = D.substring(0, D.lastIndexOf("/"));
                break
            }
            if (_ != "") for (H = 0; H < _.split("/").length; H++) B += "../";
            if (D != "") B += D + "/";
            F = B + F
        }
        $.$dpPath = F
    }

    function M(B, $, D) {
        var A = W[O], E = A[C]("HEAD").item(0), _ = A.createElement("link");
        _.href = B;
        _.rel = "stylesheet";
        _.type = "text/css";
        if ($) _.title = $;
        if (D) _.charset = D;
        E.appendChild(_)
    }

    function Y($, _) {
        E($, "onload", _)
    }

    function G($) {
        $ = $ || U;
        var A = 0, _ = 0;
        while ($ != U) {
            var D = $.parent[O][C]("iframe");
            for (var F = 0; F < D.length; F++) {
                try {
                    if (D[F].contentWindow == $) {
                        var E = V(D[F]);
                        A += E.left;
                        _ += E.top;
                        break
                    }
                } catch (B) {
                }
            }
            $ = $.parent
        }
        return {"leftM": A, "topM": _}
    }

    function V(E) {
        if (S) return E.getBoundingClientRect(); else {
            var A = {ROOT_TAG: /^body|html$/i, OP_SCROLL: /^(?:inline|table-row)$/i}, G = null, _ = E.offsetTop,
                F = E.offsetLeft, D = E.offsetWidth, B = E.offsetHeight, C = E.offsetParent;
            if (C != E) while (C) {
                F += C.offsetLeft;
                _ += C.offsetTop;
                if (C.tagName.toLowerCase() == "body") G = C.ownerDocument.defaultView;
                C = C.offsetParent
            }
            C = E.parentNode;
            while (C.tagName && !A.ROOT_TAG.test(C.tagName)) {
                if (C.scrollTop || C.scrollLeft) if (!A.OP_SCROLL.test(C.style.display)) if (!a || C.style.overflow !== "visible") {
                    F -= C.scrollLeft;
                    _ -= C.scrollTop
                }
                C = C.parentNode
            }
            var $ = Z(G);
            F -= $.left;
            _ -= $.top;
            D += F;
            B += _;
            return {"left": F, "top": _, "right": D, "bottom": B}
        }
    }

    function N($) {
        $ = $ || U;
        var _ = $[O];
        _ = _[J] && _[J].clientHeight && _[J].clientHeight <= _.body.clientHeight ? _[J] : _.body;
        return {"width": _.clientWidth, "height": _.clientHeight}
    }

    function Z($) {
        $ = $ || U;
        var B = $[O], A = B[J], _ = B.body;
        B = (A && A.scrollTop != null && (A.scrollTop > _.scrollLeft || A.scrollLeft > _.scrollLeft)) ? A : _;
        return {"top": B.scrollTop, "left": B.scrollLeft}
    }

    function D($) {
        src = $ ? ($.srcElement || $.target) : null;
        if (Q && !Q.eCont && Q.dd && Q.dd.style.display == "block" && src != Q.el) Q.cal.close()
    }

    function X() {
        Q.status = 2;
        H()
    }

    function H() {
        if (Q.flatCfgs.length > 0) {
            var $ = Q.flatCfgs.shift();
            $.el = {innerHTML: ""};
            $.autoPickDate = true;
            $.qsEnabled = false;
            K($)
        }
    }

    var R, _;

    function T(E, $) {
        B();
        Q.win = W;
        E = E || {};
        if ($) {
            if (!D()) {
                _ = _ || setInterval(function () {
                    if (U[O].readyState == "complete") clearInterval(_);
                    T(null, true)
                }, 50);
                return
            }
            if (Q.status == 0) {
                Q.status = 1;
                K({el: {innerHTML: ""}}, true)
            } else return
        } else if (E.eCont) {
            E.eCont = Q.$(E.eCont);
            Q.flatCfgs.push(E);
            if (Q.status == 2) H()
        } else {
            if (Q.status == 0) Q.status = 1;
            if (Q.status != 2) return;
            var C = A();
            if (C) {
                Q.srcEl = C.srcElement || C.target;
                C.cancelBubble = true
            }
            E.el = Q.$(E.el || Q.srcEl);
            if (!E.el || E.el && E.el.disabled || (E.el == Q.el && Q.dd.style.display != "none" && Q.dd.style.left != "-1970px")) return;
            K(E)
        }

        function D() {
            if (S && U != W && U[O].readyState != "complete") return false;
            return true
        }

        function A() {
            if (I) {
                func = A.caller;
                while (func != null) {
                    var $ = func.arguments[0];
                    if ($ && ($ + "").indexOf("Event") >= 0) return $;
                    func = func.caller
                }
                return null
            }
            return event
        }
    }

    function K(E, _) {
        for (var D in $) if (D.substring(0, 1) != "$") Q[D] = $[D];
        for (D in E) if (Q[D] === undefined) Q.errMsg = "invalid property:" + D; else Q[D] = E[D];
        Q.elProp = Q.el && Q.el.nodeName == "INPUT" ? "value" : "innerHTML";
        if (Q.el[Q.elProp] == null) return;
        if (Q.lang == "auto") Q.lang = S ? navigator.browserLanguage.toLowerCase() : navigator.language.toLowerCase();
        if (!Q.dd || Q.eCont || (Q.lang && Q.realLang && Q.realLang.name != Q.lang && Q.getLangIndex && Q.getLangIndex(Q.lang) >= 0)) {
            if (Q.dd && !Q.eCont) U[O].body.removeChild(Q.dd);
            if ($.$dpPath == "") F(A);
            var B = "<iframe src=\"" + $.$dpPath + "My97DatePicker.htm\" frameborder=\"0\" border=\"0\" scrolling=\"no\"></iframe>";
            if (Q.eCont) {
                Q.eCont.innerHTML = B;
                Y(Q.eCont.childNodes[0], X)
            } else {
                Q.dd = U[O].createElement("DIV");
                Q.dd.style.cssText = "position:absolute;z-index:19700";
                Q.dd.innerHTML = B;
                U[O].body.appendChild(Q.dd);
                Y(Q.dd.childNodes[0], X);
                if (_) Q.dd.style.left = Q.dd.style.top = "-1970px"; else {
                    Q.show();
                    C()
                }
            }
        } else if (Q.cal) {
            Q.show();
            Q.cal.init();
            if (!Q.eCont) C()
        }

        function C() {
            var F = Q.position.left, B = Q.position.top, C = Q.el;
            if (C != Q.srcEl && (C.style.display == "none" || C.type == "hidden")) C = Q.srcEl;
            var H = V(C), $ = G(W), D = N(U), A = Z(U), E = Q.dd.offsetHeight, _ = Q.dd.offsetWidth;
            if (isNaN(B)) {
                if (B == "above" || (B != "under" && (($.topM + H.bottom + E > D.height) && ($.topM + H.top - E > 0)))) B = A.top + $.topM + H.top - E - 3; else B = A.top + $.topM + H.bottom;
                B += S ? -1 : 1
            } else B += A.top + $.topM;
            if (isNaN(F)) F = A.left + Math.min($.leftM + H.left, D.width - _ - 5) - (S ? 2 : 0); else F += A.left + $.leftM;
            Q.dd.style.top = B + "px";
            Q.dd.style.left = F + "px"
        }
    }
})($dp)